package com.ruoyi.web.controller.report;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.report.domain.ReportWorkbookData;
import com.ruoyi.report.service.IReportWorkbookDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报工作簿数据Controller
 * 
 * @author sunyan
 * @date 2022-03-14
 */
@RestController
@RequestMapping("/report/workbookData")
public class ReportWorkbookDataController extends BaseController
{
    @Autowired
    private IReportWorkbookDataService reportWorkbookDataService;

    /**
     * 查询报工作簿数据列表
     */
//    @PreAuthorize("@ss.hasPermi('report:workbookData:list')")
    @GetMapping("/list")
    public TableDataInfo list(Long reportId)
    {
        startPage();
        List<String> list = reportWorkbookDataService.selectReportWorkbookDataByReportId(reportId);
        return getDataTable(list);
    }

    /**
     * 导出报工作簿数据列表
     */
//    @PreAuthorize("@ss.hasPermi('report:workbookData:export')")
//    @Log(title = "报工作簿数据", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Long reportId)
//    {
//        List<ReportWorkbookData> list = reportWorkbookDataService.selectReportWorkbookDataByReportId( reportId);
//        ExcelUtil<ReportWorkbookData> util = new ExcelUtil<ReportWorkbookData>(ReportWorkbookData.class);
//        util.exportExcel(response, list, "报工作簿数据数据");
//    }

//    /**
//     * 获取报工作簿数据详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('report:workbookData:query')")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id)
//    {
//        return AjaxResult.success(reportWorkbookDataService.selectReportWorkbookDataById(id));
//    }

    /**
     * 新增报工作簿数据
     */
    @PreAuthorize("@ss.hasPermi('report:workbookData:add')")
    @Log(title = "报工作簿数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReportWorkbookData reportWorkbookData)
    {
        return toAjax(reportWorkbookDataService.insertReportWorkbookData(reportWorkbookData));
    }

    /**
     * 修改报工作簿数据
     */
    @PreAuthorize("@ss.hasPermi('report:workbookData:edit')")
    @Log(title = "报工作簿数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReportWorkbookData reportWorkbookData)
    {
        return toAjax(reportWorkbookDataService.updateReportWorkbookData(reportWorkbookData));
    }

    /**
     * 删除报工作簿数据
     */
    @PreAuthorize("@ss.hasPermi('report:workbookData:remove')")
    @Log(title = "报工作簿数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(reportWorkbookDataService.deleteReportWorkbookDataByIds(ids));
    }
    /**
     * 获取报表分页序号
     * @param id
     * @return
     */
    @GetMapping(value = "/sheetIndex/{id}")
    public AjaxResult getSheetIndex(@PathVariable("id") Long id)
    {
        List<ReportWorkbookData> index = reportWorkbookDataService.selectReportSheetIndexByReportId(id);
        System.out.println(index);
        return AjaxResult.success(index);
    }
}
